@echo off
rem - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
rem  Package:		OurGrid 4.0
rem  Description:	This batch script is used to wait for a command execution in a 
rem                 virtual machine to exit.
rem  Copyright (c)  2007 Universidade Federal de Campina Grande 
rem - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

if %1.==/?. goto usage
if %3.==. goto usage
goto findself

:findself
set SELF=%~d0%~p0
set SHARED=ourgridshared
goto main

:main
set VMANAGE=%1
set IMAGE=%2
set TERM=%3

:loop
%VMANAGE% showvminfo %IMAGE% | find "running"
if %ERRORLEVEL% == 0 (
	if not exist %TERM% (
		call "%SELF%\sleep.bat" 2
		goto loop
	)
)
goto eof

:usage
echo usage: 1>&2
echo [CALL] %0 ^<VMANAGE COMMAND^> ^<VBOX IMAGE NAME^> ^<TERM FILE^> 1>&2
goto eof

:eof